package com.zpf.service.impl;

import com.zpf.dao.UserDao;
import com.zpf.dao.impl.UserDaoImpl1;
import com.zpf.pojo.User;
import com.zpf.service.UserService;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.util.ArrayList;
import java.util.List;

public class UserServiceImpl1 implements UserService {

//    UserDao userDao = new UserDaoImpl1();
//  注入全局属性
    private UserDao userDao;//默认值是null，要在applicationContext.xml配置,由spring实例化

    public UserDao getUserDao() {
        return userDao;
    }

    public void setUserDao(UserDao userDao) {

        System.out.println("=========UserServiceImpl1的set注入================");
        this.userDao = userDao;
    }

    @PostConstruct
    public void  init(){
        System.out.println("=====UserServiceImpl1类初始化init=======");
    }

    //    销毁方法
    @PreDestroy
    public void  destroy(){
        System.out.println("=====UserServiceImpl1类销毁destroy=======");
    }

//    业务方法
    @Override
    public void registUser() {
        userDao.insertUser();
        System.out.println("======UserService第一种实现类=======");
    }

    @Override
    public List<User> findUserAll() {
        System.out.println("============UserServiceImpl1执行了findUserAll方法===");


        return new ArrayList<User>();
    }

    @Override
    public void insertUser(User user) {
        System.out.println("============UserServiceImpl1执行了insertUser方法===");
    }

    @Override
    public void updateUser(User user) {
        System.out.println("============UserServiceImpl1执行了updateUserl方法===");
    }

    @Override
    public void deleteUser(Integer id) {
        System.out.println("============UserServiceImpl1执行了deleteUser方法===");

        //模拟发生异常
        int i = 1 / 0;
    }

    //无参构造
    public UserServiceImpl1() {
        System.out.println("======UserServiceImpl1执行构造=========");
    }
}
